package com.ncmmall.domain.business.goods.attribute;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ncmmall.domain.business.goods.Goods;
import com.ncmmall.domain.security.user.WebUser;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import javax.persistence.Entity;
import java.sql.Timestamp;
import java.util.List;

/**
 * @author linxs
 * @Description: 商品销售规格
 * @Date: 2019-07-12 21:29
 */
@Entity
@Table(name = "mall_goods_sale_attribute")
@Access(AccessType.FIELD)
public class GoodsSaleAttribute {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @JsonBackReference
    @JoinColumn(name = "goodsId")
    @OneToOne
    private Goods goods;

    /**
     * 所属商家
     */
    @JsonBackReference
    @OneToOne
    private WebUser merchant;


    /**
     * 商品规格ID
     */
    private long attributeId;

    /**
     * 商品规格名称
     */
    private String name;

    @JsonBackReference
    @ManyToOne
    @JoinColumn(name = "sale_attribute_id")
    @NotFound(action = NotFoundAction.IGNORE)
    private GoodsSaleAttribute parent;

    /**
     * 商品规格值列表
     */
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "sale_attribute_id", nullable = true)
    private List<GoodsSaleAttribute> values;

    /**
     * 创建时间，商品展示的时候需要asc排序
     */
    private Timestamp createTime;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Goods getGoods() {
        return goods;
    }

    public void setGoods(Goods goods) {
        this.goods = goods;
    }

    public long getAttributeId() {
        return attributeId;
    }

    public void setAttributeId(long attributeId) {
        this.attributeId = attributeId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public GoodsSaleAttribute getParent() {
        return parent;
    }

    public void setParent(GoodsSaleAttribute parent) {
        this.parent = parent;
    }

    public List<GoodsSaleAttribute> getValues() {
        return values;
    }

    public void setValues(List<GoodsSaleAttribute> values) {
        this.values = values;
    }

    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    public WebUser getMerchant() {
        return merchant;
    }

    public void setMerchant(WebUser merchant) {
        this.merchant = merchant;
    }
}
